home *** CD-ROM | disk | FTP | other *** search
- Path: mail2news.demon.co.uk!genesis.demon.co.uk
- From: Lawrence Kirby <fred@genesis.demon.co.uk>
- Newsgroups: comp.lang.c
- Subject: Re: C preprocessor problem
- Date: Wed, 06 Mar 96 20:26:21 GMT
- Organization: none
- Message-ID: <826143981snz@genesis.demon.co.uk>
- References: <313A3ABE.11CD@accent.net>
- Reply-To: fred@genesis.demon.co.uk
- X-NNTP-Posting-Host: genesis.demon.co.uk
- X-Newsreader: Demon Internet Simple News v1.27
- X-Mail2News-Path: genesis.demon.co.uk
-
- In article <313A3ABE.11CD@accent.net> eros-ssm@accent.net "Daniel Bolduc" writes:
-
- >In the past, I programmed with the release 3.2.4 of SCO Operating and
- >Development System. The C compiler was Microsoft C 6.0.
- >
- >With this compiler, i can use the maximum of the preprocessor without
- >problem.
- >The preprocessor is recursive, he have to resolve expression until the
- >code
- >is reduce to the simple code. With "cc" command i never had any error.
-
- The C preprocessor is not recursive in any sense that I can fathom. Ceratinly
- macro replacements can be nested but a single macro can't be expanded
- recursively.
-
- >But now, with the new compiler of SCO OpenServer, it didn't resolve the
- >expression recursively.
- >It translate expression with the appropriate code, but if the code use a
- >variable, the reference is not resolve and i get a compiler error.
-
- The new compiler correctly diagnosed a bug in your code which the old
- compiler failed to diagnose.
-
- ...
-
- >#define S_FVAL(idAlias,idFld) \
- > zaoFld##idAlias[##idFld##idAlias].u.cpValue
-
- ^^
-
- Here you are trying to paste [ to the beginning of the identifier which
- creates an illegal pp-token. It should be a separate token so remove the
- ## indicated.
-
- >#define C_FVAL(idAlias,idFld) \
- > zaoFld##idAlias[##idFld##idAlias].u.cValue
- >#define I_FVAL(idAlias,idFld) \
- > zaoFld##idAlias[##idFld##idAlias].u.iValue
- >#define L_FVAL(idAlias,idFld) \
- > zaoFld##idAlias[##idFld##idAlias].u.lValue
- >#define R_FVAL(idAlias,idFld) \
- > zaoFld##idAlias[##idFld##idAlias].u.rValue
-
- Similarly.
-
- >//=========================================================================
-
- // is a syntax error in C. If you want to write C code ise /* and */ to
- delimit comments. Compile your code forcing ANSI compliance from your
- compiler (possibly using -ansi or 'man cc' if not).
-
- >If i compile the source like this, the program works:
- >
- >#cc -E -P test.c > test2.c
- >
- >"test.c", line 123: error: invalid token: [iNumTest
- >"test.c", line 123: error: Syntax error before or at: ]
- >"test.c", line 124: error: invalid token: [cNameTest
- >"test.c", line 125: error: invalid token: [cSexTest
- >"test.c", line 126: error: invalid token: [lActiveTest
- >"test.c", line 127: error: invalid token: [rSalaryTest
- >
- >#cc test2.c
-
- In that case you are writing the preprocessor output to a file. What it can't
- write is the way you forced tokenisation with ##. The 2nd time it was compiled
- there were no ## to cause any problems.
-
- --
- -----------------------------------------
- Lawrence Kirby | fred@genesis.demon.co.uk
- Wilts, England | 70734.126@compuserve.com
- -----------------------------------------
-